package com.ryskoo.catering.dinnertabletype.repository;

import com.ryskoo.catering.dinnertabletype.domain.DinnerTableTypePO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DinnerTableTypeJPAImpl extends BasicJPAImpl<DinnerTableTypePO> implements IDinnerTableTypeRepository {
    @Override
    public List<DinnerTableTypePO> getListByVendorId(String vendorId) {
        String hql = "from DinnerTableTypePO o where o.vendorUuid = :vendorUuid";
        Query query = getH4Session().createQuery(hql);
        query.setString("vendorUuid",vendorId);
        return query.list();
    }

    @Override
    public List<String> getUuidByNameAndVendorId(String name, String vendorId) {
        String hql = "from DinnerTableTypePO o where o.vendorUuid = :vendorUuid and o.name = :name";
        Query query = getH4Session().createQuery(hql);
        query.setString("vendorUuid",vendorId);
        query.setString("name",name);
        return query.list();
    }

    @Override
    public List<String> getUuidByNameAndVendorIdForUpdate(String name, String vendorId, String uuid) {
        String hql = "from DinnerTableTypePO o where o.vendorUuid = :vendorUuid and o.name = :name and uuid != :uuid";
        Query query = getH4Session().createQuery(hql);
        query.setString("vendorUuid",vendorId);
        query.setString("name",name);
        query.setString("uuid",uuid);
        return query.list();
    }
}
